home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PCMania 48
/
PCMania CD48_1.iso
/
pcmania
/
virus48
/
antijunk.c
next >
Wrap
C/C++ Source or Header
|
1996-07-29
|
20KB
|
653 lines
/*----------------------------------------------*/
/* ANTIJUNK (c) 1996 Por Javier Guerrero Díaz
/* Rastrea el sistema en busca del virus JUNKIE.
/*
/* La sintaxis es: ANTIJUNK <unidad:\directorio>.
/* El programa buscará el virus en el boot sector de
/* la unidad especificada y en los archivos de la misma.
/* Programado con Borland C++ 5.0.
/*----------------------------------------------*/
/* Javier Guerrero Díaz */
/* ALGECIRAS */
/* (CADIZ) */
/*-------------------------------*/
#include <stdio.h>
#include <dos.h>
#include <dir.h>
#include <conio.h>
#include <bios.h>
#include <stdlib.h>
#include <direct.h>
#include <string.h>
#include <io.h>
void fin(void);
void mal(void);
void intro(void);
void buscafichero(void);
void panta(void);
void obtieneinfo(void);
void buscamem(void);
void busca(void);
void mensaje(char *mensa);
void errorhand(int);
void leeboot(void);
void buscaenboot(void);
void mataboot(void);
void analiza(void);
void encontrado(void);
void matavir(void);
void atributo(char);
union REGS registros;
char tecla,diractual[50],dirdestino[50];
int temp,infec=0,analiz=0,drive,pulsa,segmento,despl,despla,oldrive;
unsigned int corta;
unsigned long memlibre=0;
FILE *fichero;
struct ffblk arch;
struct date fecha;
struct dostime_t hora;
char far *memo;
int far *direcc,sector,cabeza,*virus;
char unidad,cambio,buffer[512],letra;
char cadena[]={ 0x2e,0x80,0x3E,0x60,0x03,0x01,0x74,0x3C,0x1E,0x06,0x50,0x56,
0x57,0xBE,0x84,0x00,0x33,0xC0,0x8E,0xD8,0xA1,0x82 };
char bytes[1024];
unsigned char jmp;
void main(argc,argv)
int argc;
char *argv[];
{
if (*argv[1]==NULL || *argv[1]=='?')
{ printf("\nANTIJUNKIE (c)1996 Por Javier Guerrero Díaz\n");
printf("Sintaxis: ANTIJUNK <unidad:\directorio>\n"); exit(-1);}
getcwd(diractual,50);
oldrive=getdisk();
_setcursortype(_NOCURSOR);
if (*argv[1]=='a' || *argv[1]=='A') { drive=1; unidad=0; }
else if (*argv[1]=='b' || *argv[1]=='B') { drive=2; unidad=1; }
if (*argv[1]=='c' || *argv[1]=='C') { drive=3; unidad=0x80; }
else if (*argv[1]=='d' || *argv[1]=='D') { drive=4; unidad=0x81; }
if (*argv[1]=='e' || *argv[1]=='E') { drive=5; unidad=0x82; }
letra=*argv[1];
if (_chdrive(drive)==-1) { printf("\nError. No puedo acceder a la unidad ");
printf("%s.\n",argv[1]); mal(); }
if (chdir(argv[1])==-1) { printf("\nError. No puedo acceder al directorio ");
printf("%s.\n",argv[1]); mal(); }
getcwd(dirdestino,50);
intro();
panta();
buscamem();
buscafichero();
fin();
}
void matavir(void)
{
int res,handle;
int far *word1;
int far *word2;
char prot='N';
char far *atr;
atr=(char far *)&arch.ff_attrib;
if ((*atr & 1)) { *atr=*atr ^ 1; prot='Y'; }
word1=(int far*)MK_FP(FP_SEG(bytes),FP_OFF(bytes)+25);
word2=(int far*)MK_FP(FP_SEG(bytes),FP_OFF(bytes)+30);
asm {
push ax
push bx
push cx
push dx
push si
push di
push ds
push es
pushf
mov ax,seg bytes
mov ds,ax
mov es,ax
mov cx,01F4h
mov si,offset bytes
add si,0Dh
mov di,offset bytes
add di,07h
mov bx,es:[di]
bucle:
xor word ptr es:[si],bx
inc si
inc si
loop bucle
popf
pop es
pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
}
rewind(fichero); res=putw(*word1,fichero);
res=putw(*word2,fichero); rewind(fichero);
res=fseek(fichero,corta,SEEK_SET);
if (res!=0) {
mensaje("Error gestionando fichero!."); mal();
}
handle=fileno(fichero); res=chsize(handle,corta);
if (res!=0) {
mensaje("Error al modificar el tamaño del archivo."); mal();
}
if (prot=='Y') *atr=*atr | 1;
mensaje("OK!. Virus eliminado del fichero.");
}
void analiza(void)
{
unsigned char dummy;
int res,resto;
unsigned int salto;
int far *marca;
marca=(int far*)MK_FP(FP_SEG(bytes),FP_OFF(bytes)); marca++; rewind(fichero);
resto=arch.ff_fsize%16; if (resto!=3) goto sale;
dummy=fgetc(fichero); if (dummy!=0xE9) goto sale;
salto=getw(fichero); corta=salto+3;
salto+=3; rewind(fichero);
res=fseek(fichero,salto,SEEK_SET);
if (res!=0) {
mensaje("Error gestionando fichero!."); mal();
}
salto=getw(fichero);
res=fread(bytes,1,1024,fichero);
if (res!=1024) {
mensaje("Error leyendo archivo!."); mal();
}
if (*marca!=0x01F4) goto sale;
marca++; if (*marca!=0x8126) goto sale;
infec++; encontrado();
textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta(); obtieneinfo();
sale:
}
void encontrado(void)
{
window(22,8,57,20);
textattr(WHITE|RED<<4);
cprintf("╔═══════════╦══════════╦═══════════╗");
cprintf("║ ║ ATENCION ║ ║");
cprintf("║ ╚══════════╝ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ PULSE LA TECLA 'SUPR' PARA MATAR ║");
cprintf("║ EL VIRUS O CUALQUIER OTRA PARA ║");
cprintf("║ IGNORAR ESTE FICHERO. ║");
cprintf("╚══════════════════════════════════╝");
gotoxy(3,5); cprintf("SE DETECTO LA MARCA DE INFECCION");
gotoxy(3,6); cprintf(" PROPIA DEL VIRUS 'JUNKIE',");
gotoxy(3,7); cprintf(" EN ARCHIVO:");
textattr(YELLOW|RED<<4); gotoxy(19,7); cprintf("%-12s",arch.ff_name);
textattr(WHITE|BLUE<<4); window(1,1,80,25);
mensaje("Atención: Fichero infectado por el virus !.");
tecla: pulsa=bioskey(0);
switch (pulsa)
{
case 0x5300: matavir();
break;
default: break;
}
}
void mataboot(void)
{
unsigned char media;
direcc=(int far*)MK_FP(segmento,despl);
memo=(char far*)MK_FP(segmento,despl); memo+=0x15; media=*memo;
if (media==0xF9)
{ registros.h.cl=8; registros.h.ch=0x4F;
registros.h.dh=1; registros.h.dl=unidad; }
else if (media==0xF0)
{ memo=(char far*)MK_FP(0x40,0x90); if (*memo==0x97) registros.h.cl=8;
else registros.h.cl=0x11;
registros.h.ch=0x4F; registros.h.dh=1; registros.h.dl=unidad; }
else if (unidad!=0 || unidad!=1)
{ registros.x.cx=4; registros.h.dh=0; registros.h.dl=unidad; }
virus=malloc(1024);
if (virus==NULL) {
mensaje("Error: No se pudo reservar memoria para lectura.");
mal(); }
_ES=_DS; registros.x.ax=0x0202; registros.x.bx=virus;
int86(0x13,®istros,®istros);
if (registros.x.cflag!=0) {
mensaje("Error: No se pudo leer cuerpo del virus."); free(virus); mal(); }
asm {
push ax
push bx
push cx
push dx
push si
push di
push ds
push es
pushf
mov ax,seg virus
mov ds,ax
mov es,ax
mov cx,01F4h
mov si,virus
add si,0Fh
mov di,virus
add di,09h
mov bx,es:[di]
bucle:
xor word ptr es:[si],bx
inc si
inc si
loop bucle
mov ax,seg virus
mov ds,ax
mov si,virus
add si,0378h
mov ax,seg direcc
mov es,ax
mov di,word ptr direcc
movsw
mov di,word ptr direcc
add di,60h
cld
mov cx,10h
rep movsw
popf
pop es
pop ds
pop di
pop si
pop dx
pop cx
pop bx
pop ax
}
registros.x.ax=0x0301; registros.x.bx=despl; registros.x.cx=0x0001;
registros.h.dh=0; registros.h.dl=unidad; _ES=_DS;
int86(0x13,®istros,®istros);
if (registros.x.cflag!=0) {
mensaje("Error: No se pudo corregir boot sector."); free(virus); mal(); }
free(virus); textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta(); obtieneinfo();
}
void buscaenboot(void)
{
char flag='N';
direcc=(int far*)MK_FP(segmento,despl);
if (*direcc!=0x5EEB) flag=='N';
else { direcc+=0x30; if (*direcc==0xFF33) flag='Y'; }
if (flag=='Y') {
window(17,7,63,15); textattr(WHITE|RED<<4); putch(7);
cprintf("╔═════════════════════════════════════════════╗");
cprintf("║ Atención: Encontrada la rutina de infección ║");
cprintf("║ propia del virus JUNKIE en el boot sector ║");
cprintf("║ de la unidad %c: . ║",letra);
cprintf("║ Esta unidad se encuentra infectada por ║");
cprintf("║ el virus. Pulse 'SUPR' para eliminarlo ║");
cprintf("║ y comprobar los archivos de la unidad. ║");
cprintf("╚═════════════════════════════════════════════╝");
mensaje("¡ Sector de arranque infectado !"); }
else { window(17,7,63,15); textattr(WHITE|CYAN<<4);
cprintf("╔═════════════════════════════════════════════╗");
cprintf("║ OK! El sector de arranque de la unidad %c: ║",letra);
cprintf("║ no se encuentra infectado por el virus ║");
cprintf("║ JUNKIE.El siguiente paso consistirá ║");
cprintf("║ en comprobar los archivos del directorio ║");
cprintf("║ especificado para determinar si existe sín- ║");
cprintf("║ toma de infección en los mismos. ║");
cprintf("╚═════════════════════════════════════════════╝");
window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
cprintf(" ");
gotoxy(24,23); cprintf("OK. Boot sector limpio.");
sleep(4); gotoxy(24,23);
cprintf(" ");
textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta(); goto salida;
}
tecl: pulsa=bioskey(0);
switch (pulsa)
{
case 283: fin();
break;
case 0x5300: mataboot();
goto salida;
default: goto tecl;
}
salida:
}
void buscamem(void)
{
window(18,7,62,11);
textattr(WHITE|BLUE<<4);
cprintf("╔═══════════════════════════════════════════╗");
cprintf("║ Buscando virus JUNKIE en memoria. ║");
cprintf("║ Analizando la RAM ..... ║");
cprintf("╚═══════════════════════════════════════════╝");
sleep(1);
busca();
}
void busca(void)
{
char far *cop;
char dummy;
direcc=(int far *)MK_FP(0x0000,0x0413);
if (*direcc==0x27D)
{
window(17,7,63,15); textattr(YELLOW|RED<<4); putch(7);
cprintf("╔═════════════════════════════════════════════╗");
cprintf("║ Atención: La cantidad de memoria conven- ║");
cprintf("║ cional en el sistema es inferior a 640 Kb; ║");
cprintf("║ como otros muchos virus, el JUNKIE produ- ║");
cprintf("║ ce este efecto. Se realizará un analisis ║");
cprintf("║ de la memoria para determinar la existencia ║");
cprintf("║ en la misma del virus JUNKIE. ║");
cprintf("╚═════════════════════════════════════════════╝");
mensaje("Encontrado síntoma de infección vírica."); sleep(5);
textattr(LIGHTGRAY|BLACK<<4); clrscr(); panta();
}
else goto noresid;
segmento=*direcc*64;
memo=(char far *)MK_FP(segmento,0x1EA);
cop=(char far *)MK_FP(segmento,586);
for (temp=0;temp<sizeof cadena;temp++)
{
if (*memo!=cadena[temp]) goto noresid;
else memo++;
}
window(14,7,66,21); textattr(YELLOW|RED<<4);
putch(7);
cprintf("╔═══════════════════════════════════════════════════╗");
cprintf("║ Atención: Virus JUNKIE detectado en la ║");
cprintf("║ dirección de memoria : %X:0000 ║",segmento);
cprintf("╟───────────────────────────────────────────────────╢");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("║ ║");
cprintf("╚═══════════════════════════════════════════════════╝");
window(15,11,65,20); textattr(WHITE|RED<<4);
for (temp=0;temp<459;temp++)
{ dummy=*cop; if (dummy<32) dummy='.'; cprintf("%c",dummy); cop++; }
mensaje("¡ Virus encontrado en memoria !"); textattr(LIGHTGRAY|BLACK<<4);
sleep(5); clrscr(); panta();
window(17,7,63,15); textattr(WHITE|GREEN<<4);
cprintf("╔═════════════════════════════════════════════╗");
cprintf("║ Atencion: El virus se encuentra en memoria. ║");
cprintf("║ Para el correcto funcionamiento de esta va- ║");
cprintf("║ cuna es muy importante que el virus no esté ║");
cprintf("║ residente en la memoria; se recomienda ini- ║");
cprintf("║ciar el sistema con un disquete de DOS limpio║");
cprintf("║ y protegido, y ejecutar de nuevo la vacuna. ║");
cprintf("╚═════════════════════════════════════════════╝");
window(23,13,62,13); textattr(YELLOW|BLUE<<4); exit(0);
noresid:
window(18,7,62,11);
cprintf("╔═══════════════════════════════════════════╗");
cprintf("║ OK !. No se encontró el virus en RAM. ║");
cprintf("║ Analizando boot de unidad %c: .... ║",letra);
cprintf("╚═══════════════════════════════════════════╝");
leeboot(); buscaenboot();
}
void obtieneinfo(void)
{
getdate(&fecha);
_dos_gettime(&hora);
registros.h.ah=0x48; registros.x.bx=0xFFFF;
int86(0x21,®istros,®istros);
memlibre=registros.x.bx; memlibre*=16;
gotoxy(14,11); cprintf("%02d/%02d/%d",fecha.da_day,fecha.da_mon,fecha.da_year);
gotoxy(34,11); cprintf("%02d:%02d:%02d",hora.hour,hora.minute,hora.second);
gotoxy(62,11); cprintf("%ld",memlibre); gotoxy(32,13); cprintf("%s",dirdestino);
}
void buscafichero(void)
{
char far *atr,prot='N';
temp=findfirst("*.*",&arch,0);
while (!temp)
{ atr=(char far *)&arch.ff_attrib;
if ((*atr & 1)) { prot='Y'; atributo((*atr ^ 1)); }
obtieneinfo();
fichero=fopen(arch.ff_name,"r+b");
if (fichero==NULL)
{ gotoxy(24,23);
cprintf(" ");
gotoxy(24,23); cprintf("Error abriendo fichero!"); putch(7);
sleep(1); gotoxy(24,23);
cprintf(" ");
}
analiz++;
gotoxy(28,15);
cprintf("%-12s",arch.ff_name);
gotoxy(62,15);
cprintf("%-8ld",arch.ff_fsize);
gotoxy(33,17);
cprintf("%-3d",analiz);
gotoxy(64,17);
cprintf("%-3d",infec);
analiza();
fclose(fichero);
if (prot=='Y') { atr=(char far *)&arch.ff_attrib;
atributo((*atr | 1)); prot='N'; }
temp=findnext(&arch);
}
setdisk(oldrive);
chdir(diractual);
}
void leeboot(void)
{
int resultado2;
short resultado1;
segmento=FP_SEG(buffer); despl=FP_OFF(buffer);
direcc=(char far *)MK_FP(segmento,despl);
window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
cprintf(" ");
gotoxy(24,23); cprintf("Leyendo boot..."); sleep(1);
gotoxy(24,23);
cprintf(" ");
asm push es
asm push ds
asm mov ah,0
asm mov dl,byte ptr unidad
asm int 13h
resultado1=_AH;
if (resultado1 !=0) errorhand(resultado1);
asm mov ah,15h
asm mov dl,byte ptr unidad
asm int 13h
asm mov byte ptr cambio,ah
asm mov ah,2
asm mov dl,byte ptr unidad
asm mov dh,0
asm mov ch,0
asm mov cl,1
asm mov al,1
asm mov es,segmento
asm mov bx,despl
asm int 13h
asm mov resultado2,ax
if (unidad==0 && resultado2 !=0x0001)
errorhand(resultado2);
else if (unidad==1 && resultado2 !=0x0001)
errorhand(resultado2);
else if (unidad==0x80 && resultado2!=0)
errorhand(resultado2);
else if (unidad==0x81 && resultado2!=0)
errorhand(resultado2);
asm
{
mov cx,0200h
mov ax,segmento
mov ds,ax
mov si,despl
mov ax,seg bytes
mov es,ax
mov di,offset bytes
rep movsb
pop ds
pop es
}
}
void intro(void)
{
clrscr(); gotoxy(20,9); textattr(YELLOW|BLUE<<4);
cprintf("╔═════════════════════════════════════╗\n"); gotoxy(20,10);
cprintf("║ ANTIJUNKIE ║\n"); gotoxy(20,11);
cprintf("║ (c) 1996 Por Javier Guerrero Diaz. ║\n"); gotoxy(20,12);
cprintf("║ Rastrea los archivos de la unidad ║\n"); gotoxy(20,13);
cprintf("║ especificada como parámetro a la ║\n"); gotoxy(20,14);
cprintf("║ busqueda del virus JUNKIE. ║\n"); gotoxy(20,15);
cprintf("╚═════════════════════════════════════╝\n");
textattr(LIGHTGRAY|BLACK<<4);tecla=getch();
clrscr();
}
void panta(void)
{
window(20,2,60,7);
gotoxy(1,1);
textattr(YELLOW|BLUE<<4);
cprintf("╔═══════════════════════════════════════╗");
cprintf("║ DETECTOR/VACUNA PARA EL VIRUS JUNKIE ║");
cprintf("║ (C) Por Javier Guerrero Diaz ║");
cprintf("╚═══════════════════════════════════════╝");
window(5,8,75,20);
cprintf("╔═════════════════════════════════════════════════════════════════════╗");
cprintf("║ ANALISIS DE ARCHIVOS ║");
cprintf("║ ║");
cprintf("║ Fecha: Hora: Memoria Libre: bytes ║");
cprintf("║ ║");
cprintf("║ Directorio de Búsqueda: ║");
cprintf("║ ║");
cprintf("║ Nombre de Archivo : Longitud Archivo: ║");
cprintf("║ ║");
cprintf("║ Archivos Analizados: Archivos Infectados: ║");
cprintf("║ ║");
cprintf("╚═════════════════════════════════════════════════════════════════════╝");
window(1,22,80,25);
cprintf("╔══════════════════════════════════════════════════════════════════════════════╗");
cprintf("║ RESULTADO OPERACION: ║");
cprintf("╚══════════════════════════════════════════════════════════════════════════════╝");
textattr(WHITE|BLUE<<4); window(1,1,80,25);
}
void errorhand(numerror)
int numerror;
{
switch(numerror)
{
case 0x0100: mensaje("Error: Función no permitida.");
break;
case 0x0200: mensaje("Error: Marca de direcciones no encontrada.");
break;
case 0x0300: mensaje("Error: Disquete protegido contra escritura.");
break;
case 0x0400: mensaje("Error: Sector no encontrado.");
break;
case 0x0600:
if (cambio!=2)
{ mensaje("Error: Disco retirado, pulsa tecla para repetir lectura.");
getch(); }
leeboot(); buscaenboot();
break;
case 0x0800: mensaje("Error: Desbordamiento de DMA.");
break;
case 0x0900: cprintf("Error: Superado el límite de 64k de segmento.");
break;
case 0x0c00: mensaje("Error: Tipo de entorno no hallado.");
break;
case 0x1000: mensaje("Error: Fallo de lectura.");
break;
case 0x2000: mensaje("Error: Fallo de controladora de disco.");
break;
case 0x4000: mensaje("Error: Pista no encontrada.");
break;
case 0x8000: mensaje("Error: Time Out; unidad no responde.");
break;
default: mensaje("Error: Fallo general.");
break;
}
mal();
}
void mensaje(mensa)
char mensa[50];
{
window(1,1,80,25); textattr(WHITE|BLUE<<4); gotoxy(24,23);
cprintf(" ");
gotoxy(24,23); cprintf("%s",mensa); putch(7);
sleep(1); gotoxy(24,23);
cprintf(" ");
}
void fin(void)
{
_setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
exit(0);
}
void mal(void)
{
setdisk(oldrive);
_setcursortype(_NORMALCURSOR); textattr(LIGHTGRAY|BLACK<<4);
printf("\nPrograma finalizado anormalmente.\n");
exit(-1);
}
void atributo(attrib)
char attrib;
{
int nombre;
registros.x.ax=0x4301; registros.x.cx=attrib;
nombre=FP_OFF(&arch.ff_name); registros.x.dx=nombre;
int86(0x21,®istros,®istros);
if (registros.x.cflag!=0) {
mensaje("Error: No se pudo cambiar atributo de fichero."); mal(); }
}